﻿// -----------------------------------------------------------------------
// <copyright file="TouchFile.cs" company="Microsoft">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace TouchExplorer
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO;
    using System.Windows.Media.Imaging;
    using System.ComponentModel;
    using Microsoft.WindowsAPICodePack.Shell;
using System.Windows.Threading;
    using System.Diagnostics;
    using System.Windows;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class TouchFile : TouchFileElementBase
    {
        private static BitmapImage _defaultImage = new BitmapImage(new Uri(@"..\Icons\playlist.png", UriKind.Relative));

        public FileInfo Info { get; private set; }

        public string FileDescription
        {
            get
            {
                return string.Format("last updated : {0}, size : {1}", Info.LastWriteTime, Info.Length);
            }
        }
        
        public TouchFile(FileInfo nfo)
        {
            Info = nfo;
            FullPath = nfo.FullName;
            Name = Path.GetFileNameWithoutExtension(nfo.FullName);            
        }

        public TouchFile(ShellObject shell)
        {
            Info = new FileInfo(shell.ParsingName);
            this.Shell = shell;
            FullPath = Info.FullName;
            Name = Path.GetFileNameWithoutExtension(Info.FullName);            
        }

        public override bool Exists
        {
            get
            {
                if (string.IsNullOrEmpty(FullPath)) return false;

                return File.Exists(FullPath);
            }
        }

        public void Run()
        {
            try
            {
                if (File.Exists(FullPath))
                {
                    Process.Start(FullPath);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Oups cannot open this file...");
            }
        }
    }
}
